﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Cheetah_Fast_Banking_App.Cryptography
{
    public class SaltGenerator
    {
        // ignore idiot inputs for now... (ie., null Encoding, zero or negative Length)

        private RNGCryptoServiceProvider _rng;

        public Encoding Encoding { get; set; }

        public int Length { get; set; }

        public SaltGenerator()
            : this (Encoding.Default, 16)
        { }

        public SaltGenerator(Encoding encoding, int length)
        {
            this.Encoding = encoding;
            this.Length = length;

            this._rng = new RNGCryptoServiceProvider();
        }

        public string GenerateRandomSalt()
        {
            byte[] saltBytes = new byte[this.Length];
            _rng.GetNonZeroBytes(saltBytes);
            return Convert.ToBase64String(saltBytes);
        }
    }
}
